const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

class FolderNode {
    constructor(fileName, filePath){
        this.fileName = fileName
        this.filePath = filePath
        this.child = []
        this.parent = null
    }

    findNode(fileName){
        return this.child.find((obj)=>
            obj.fileName === fileName
        ) || null
    }

    addChild(fileName){
        if(!this.findNode(fileName)) {
            const newNode = new FolderNode(fileName, this.filePath + fileName + "/")
            newNode.parent = this
            this.child.push(newNode)
        }
    }
}

const root = new FolderNode("", "/")
let current = root

rl.on("line", (line)=>{
    const [command, dirName] = line.trim().split(" ")
    if(command === "mkdir" && dirName && /^[a-z]+$/.test(dirName) ) {
            current.addChild(dirName)
    } else if (command === "cd") {
        if(dirName === "..") {
            if(current.parent){
                current = current.parent; // 上级
            }
        } else {
                const findNode = current.findNode(dirName);
                if(findNode) current = findNode // 进入子目录
        }

    } else if (command === "pwd") {
        console.log(current.filePath) // 输出
    }
})
